package com.yzqp.common.result;


/**
 * jsonResult构建工具类
 */
public class WebJsonResultUtil {

    //正确码
    public static final int SUCCESS = 0;
    //错误码
    public static final int ERR = -1;
    //系统错误
    public static final int LOGIN_ERR = -10;

    //默认成功消息
    public static final String DEFAULT_SUCCESS_MESSAGE = "成功";


    //成功的jsonResult
    public static <T> WebJsonResult<T> success() {
        WebJsonResult<T> result = new WebJsonResult<>();
        result.setState(SUCCESS);
        result.setSuccess(true);
        return result;
    }

    //成功的jsonResult
    public static <T> WebJsonResult<T> success(T data) {
        WebJsonResult<T> result = new WebJsonResult<>();
        result.setState(SUCCESS);
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    //成功的jsonResult
    public static <T> WebJsonResult<T> success(String message, T data) {
        WebJsonResult<T> result = new WebJsonResult<>();
        result.setState(SUCCESS);
        result.setSuccess(true);
        result.setData(data);
        result.setMessage(message);
        return result;
    }

    //错误的jsonResult
    public static <T> WebJsonResult<T> error(String message) {
        WebJsonResult<T> result = new WebJsonResult<>();
        result.setState(ERR);
        result.setMessage(message);
        result.setSuccess(false);
        return result;
    }

    //错误的jsonResult
    public static <T> WebJsonResult<T> errorLogin(String message) {
        WebJsonResult<T> result = new WebJsonResult<>();
        result.setState(LOGIN_ERR);
        result.setSuccess(false);
        return result;
    }


}
